<?php
class TValidate
{
	private $path;
	private $cmd = array();

	public function __construct(){
		$this->path = PLUGINS_DIR.'/TValidate/';
		$files = scandir($this->path);
		foreach($files as $file){
			if(is_file($this->path.$file)){
				$w = str_replace('TValidate', '' ,$file);
				$w = str_replace('.php', '', $w);
				$this->cmd[$w] = $file;
			}
		}
	}

	public function chk($w,$v,$arg){
		$c = 'TValidate'.$w;
		if(!class_exists($c)) require_once($this->path.$this->cmd[$w]);
		if(!($this->cmd[$w] instanceof TValidate)) $this->cmd[$w] = new $c;
		return $this->cmd[$w]->act($v,$arg);
	}

	public static function chkEmpty($val, $errno = 1){
		if(is_null($val) || strlen($val) == 0){
			return $errno;
		}elseif(is_array($val) && count($val) == 0){
			return $errno;
		}
		return false;
	}
}
